package lazy;

public class LazySingleton {

    private volatile  static LazySingleton instance ;

    //构造方法私有化
    private  LazySingleton(){

    }

    public static LazySingleton getInstance(){
        if(instance==null){
            synchronized (LazySingleton.class){
                if(instance==null){
                    instance = new LazySingleton();
                }
            }
        }
        return instance;
    }


    public static void main(String[] args) {
        for(int i=0;i<4;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(LazySingleton.getInstance());
                }
            }).start();
        }
    }
}
